package collection;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Cheng Jun
 * Description: LinkedHashMap 源码学习
 * A special constructor is provided to create a linked hash map whose order of iteration is the order in which
 * its entries were last accessed, from least-recently accessed to most-recently (access-order).
 * This kind of map is well-suited to building LRU caches.
 * <p>
 * LinkedHashMap 的 accessOreder 为false时，节点的顺序就是插入的顺序，
 * 为true时，节点之间的顺序变成 访问时产生的顺序，最近被访问的数据会被放在双向链表的最后端
 * @version 1.0
 * @date 2021/11/16 21:51
 * @see LinkedHashMap
 */
public class LinkedHashMapStudy {

    public static void main(String[] args) {

        LinkedHashMap<String, String> accessOrderFalse = new LinkedHashMap<>(4, 0.75f, false);
        LinkedHashMap<String, String> accessOrderTrue = new LinkedHashMap<>(4, 0.75f, true);
        accessOrderFalse.put("HUAWEI", "华为全球第一");
        accessOrderFalse.put("XIAOMI", "小米中国第一");
        accessOrderFalse.put("OPPO", "OPPO不咋滴");
        accessOrderFalse.put("APPLE", "苹果");

        accessOrderTrue.put("HUAWEI", "华为全球第一");
        accessOrderTrue.put("XIAOMI", "小米中国第一");
        accessOrderTrue.put("OPPO", "OPPO不咋滴");
        accessOrderTrue.put("APPLE", "苹果");

        accessOrderFalse.get("HUAWEI");
        accessOrderTrue.get("HUAWEI");
    }


}
